package cn.josh.action;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.josh.bean.Ec_user;
import cn.josh.service.Ec_userService;
import cn.josh.servicelmpl.Ec_userServiceImpl;

/**
 * Servlet implementation class RegisterServlet
 */
@WebServlet("/RegisterServlet")
public class RegisterServlet extends HttpServlet 
{
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		
		//取得前端信息
		String userName = request.getParameter("userName");
		String password = request.getParameter("password");
		String realName = request.getParameter("realName");
		String sex = "0";
		String location = request.getParameter("location");
		String phone = request.getParameter("phone");
		
		System.out.println(
							userName + "\n" + password + "\n" 
							+ realName + "\n" + sex+ "\n" 
							+ location + "\n" + phone
						   );
		
		//将前端信息封装
		Ec_user user = new Ec_user();
		user.setLogin_name(userName);
		user.setPassword(password);
		user.setName(realName);
		user.setSex(sex);
		user.setAddress(location);
		user.setPhone(phone);
		user.setRole("1");
		
		//将封装信息传给数据库操作类
		Ec_userService service = new Ec_userServiceImpl();
		service.register(user);

		//跳转到登陆界面
		response.sendRedirect("/ShoppingWebsite/LoginServlet?userName=" + userName + "&password=" + password);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		
		doGet(request, response);
	}

}
